package com.sec.etech.employeesync.handler;

import com.sec.etech.employeesync.mapper.OrgEmployeeZProfessionalTitleMapper;
import com.sec.etech.employeesync.util.ConfigHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Component
@Slf4j
public class ProfessionalTitleHandler implements ConfigHandler {

    @Resource
    private OrgEmployeeZProfessionalTitleMapper professionalTitleMapper;

    @Override
    public Long createConfig(String... params) {
//        String name = params[0];
//        OrgEmployeeZProfessionalTitle professionalTitle = new OrgEmployeeZProfessionalTitle();
//        professionalTitle.setName(name);
//        professionalTitle.setActive(1);
//        professionalTitleMapper.insert(professionalTitle);
//        log.info("新增职称配置:name={}", name);
//
//        return professionalTitle.getProfessionalTitleId();

        return null;
    }

    @Override
    public List<ConfigEntry> getAllConfigs() {
        return professionalTitleMapper.selectList(null).parallelStream()
                .map(item -> {
                    ConfigEntry entry = new ConfigEntry();
                    entry.setId(item.getProfessionalTitleId());
                    entry.setParams(new String[]{item.getCode()});
                    return entry;
                })
                .collect(Collectors.toList());
    }
}
